<body>
<p>This tests that keydown events aren't sent to the main frame for command key presses that occur when a subframe is first responder.  To run it manually, click inside the subframe, type a few characters, then do Command-A to Select All.  Only the subframe should report a keydown event.</p>
<iframe id="iframe" style="border: 1px solid black;" src="../../editing/resources/contenteditable-iframe-src.html"></iframe>
<ul id="console"></ul>

<script>
function log(str) {
    var console = document.getElementById("console");
    var li = document.createElement("li");
    li.appendChild(document.createTextNode(str));
    console.appendChild(li);
}

function addEventListeners() {
    window.addEventListener("keydown",
    function(e) {
        log("keydown in mainframe: " + e);
    },
    false);

    window.frames[0].addEventListener("keydown",
    function(e) {
        log("keydown in subframe: " + e);
    },
    false);
}

function runTest() {
    addEventListeners();

    if (!window.testRunner)
        return;

    var iframe = document.getElementById("iframe");
    var x = iframe.offsetParent.offsetLeft + iframe.offsetLeft + iframe.offsetWidth / 2;
    var y = iframe.offsetParent.offsetTop + iframe.offsetTop + iframe.offsetHeight / 2;

    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    eventSender.mouseUp();

    window.frames[0].document.execCommand("InsertText", false, "This sentence should not end with a period.");
    // Move backward by one character.
    eventSender.keyDown("ArrowLeft");
    // Delete forward by one character.
    eventSender.keyDown("Delete");

    log(window.frames[0].document.body.innerText);
    testRunner.notifyDone();
}

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}
window.onload = runTest;
</script>
</body>
